#include <iostream>
#include <cstring>

#define NAMESIZE	32

using namespace std;

class Person {
	// public:
	// protected:
	private:
		// 成员变量
		int id;
		char name[NAMESIZE];
	public:
		Person(int id_arg, const char *name_arg);
		// 成员方法
		virtual void show(); // 虚函数
		int getId() const {return id;}
		const char * getName() const{return (const char *)name;}
};

class Student : public Person {
	private:
		float score;
	public:
		Student(int id_arg, const char *name_arg, float score_arg);
		void show();
};

Person::Person(int id_arg, const char *name_arg): id(id_arg)
{
	strncpy(name, name_arg, NAMESIZE);
}

// 只能用初始化列表的方式调用基类的构造方法，初始化继承来的private成员
Student::Student(int id_arg, const char *name_arg, float score_arg) : Person(id_arg, name_arg)
{
	score = score_arg;
}

void Person::show()
{
	cout << id << ", " << name << endl;
}

void Student::show()
{
	cout << "id:" << getId() << endl;
	cout << "name:" << getName() << endl;
	cout << "score:" << score << endl;
}

int main(void)
{
	Student s1(1, "派生类对象", 90);
	Person p1(2, "基类对象");
	Person *p;

	// s1.id = 1;
	// strncpy(s1.name, "继承", NAMESIZE);

	s1.Person::show();
	s1.show();

	p = &p1;
	p->show();
	p = &s1;
	p->show(); //?????????? 应该调用的学生对象的show方法

	return 0;
}

